<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /*
        创建函数，生成当前时间字符串，
        2021-10-19 10:17:20
        作为函数的返回值返回
    */


    function identify(num){
        return num<10? "0"+num :num;
    }
    function createDate(){
        var date1 = new Date();
        //毫秒
        var min = date1.getMilliseconds();
        var date2 = [date1.getFullYear(),date1.getMonth()+1,date1.getDate()] 
        var date2Str = date2.join("-");

        var time1 = [date1.getHours(),date1.getMinutes(),date1.getSeconds()]
        var time1Str = time1.join(":");
        console.log(date2Str,time1Str);
    }
    createDate();

    document.write((new Date).toLocaleString());

</script>
</html>